<template>
  <view v-if="shenheStatus == 0" class="allorder">
    <scroll-view
      :scroll-y="true"
      @scrolltolower="scrollPageBottom"
      style="height: 100vh"
    >
      <template v-if="orderList.length > 0">
        <!-- 列表渲染订单 -->
        <view v-for="(orderitem, orderindex) in orderList" :key="orderindex">
          <orderItem
            :orderitem="orderitem"
            :orderindex="String(orderindex)"
            @toOrder="toOrder"
            @handleConfirm="handleConfirm"
            @handleCancle="handleCancle"
          ></orderItem>
        </view>
      </template>
      <u-empty :text="$t('common.noDeal')" mode="list" v-else></u-empty>
    </scroll-view>
  </view>
  <Shenhe v-else-if="shenheStatus == 1"></Shenhe>
</template>

<script>
import Shenhe from "@/components/shenhe/shenhe";
import orderItem from "../components/alipay/order-item.vue";

export default {
  components: {
    orderItem,
    Shenhe
  },
  data() {
    return {
      orderList: [],
      page: 1,
      totalPage: 0
    };
  },
  onLoad(t) {},
  onShow() {
    // 判断是否登录
    const isLogin = this.$utils.isLogin();
    if (isLogin) {
      this.getOrder({ page: this.page });
    }
  },
  watch: {},
  methods: {
    // 滚动至列表底部
    scrollPageBottom() {
      this.page++;
      if (this.page > this.totalPage) return;
      this.getOrder({
        page: this.page,
        loadmMore: true
      });
    },
    getOrder(params) {
      this.$allrequest.alipay.getOrderList(params, true).then((res) => {
        if (!res.code && res.data) {
          if (params.loadmMore) {
            this.orderList = [...this.orderList, ...res.data.list];
          } else {
            this.orderList = res.data.list;
          }
          this.totalPage = res.data.page_count;
        }
      });
    },
    // 跳转订单详情
    toOrder(e) {
      let item = e.item;
      uni.navigateTo({
        url: `/alipay-order/order/order?order_id=${item.id}&is_pay=${item.is_pay}`
      });
    },
    handleConfirm(e) {},
    handleCancle(e) {}
  }
};
</script>

<style lang="scss" scoped>
.allorder {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background-color: #f2f2f2;
}

.scroll-item {
  width: 100%;
  height: 100%;
}
</style>
